package cn.shujuhai.workflow.controller.flow;

import cn.shujuhai.common.domain.PageRequest;
import cn.shujuhai.common.pluging.data.ResultVo;
import cn.shujuhai.workflow.service.FlowDefinitionService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: ZhangDeZhong
 * @Date: 2025/3/18 16:19
 * @Description:
 **/

@RestController
@RequestMapping("/workflow/flowDefinition")
@RequiredArgsConstructor
public class FlowDefinitionController {

    private final FlowDefinitionService flowDefinitionService;

    /**
     * 分页查询流程定义列表
     */
    @GetMapping("/list")
    public ResultVo<?> flowDefinitionList(@Valid PageRequest pageRequest,
                                          @RequestParam(defaultValue = "") String search) {
        return this.flowDefinitionService.flowDefinitionList(pageRequest.getPageNum(), pageRequest.getPageSize(), search);
    }

    @PostMapping("/add")
    public ResultVo<?> saveFlowDefinition(@RequestBody Map<String, String> event) {
        return this.flowDefinitionService.saveFlowDefinition(event);
    }

    @PostMapping("/update")
    public ResultVo<?> updateFlowDefinition(@RequestBody Map<String, String> event) {
        return this.flowDefinitionService.updateFlowDefinition(event);
    }

}
